package com.dsz.usercenter.exception;

import com.dsz.usercenter.common.BaseResponse;
import com.dsz.usercenter.common.ErrorCode;
import com.dsz.usercenter.common.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHanlder(BusinessException e) {
        log.error("businessException: " + e.getMessage(), e);
        return ResultUtil.fail(e.getCode(), e.getMessage(), e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHanlder(RuntimeException e) {
        log.error("runtimeException: " + e.getMessage(), e);
        return ResultUtil.fail(ErrorCode.SYSTEM_ERROR);
    }
}
